package com.sang.database;

import com.sang.db.bean.Vertex;
import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

/**
 * identify the regular of data convert
 * 
 * @author sang
 * 
 */
public class VertexTupleBinding extends TupleBinding {

	public Object entryToObject(TupleInput in) {
		// order is very important
		Vertex v = new Vertex();
		v.setId(in.readInt());
		v.setDescription(in.readString());
		return v;
	}

	public void objectToEntry(Object obj, TupleOutput out) {

		// invert object to class ObjectData
		Vertex v = (Vertex) obj;

		// Write the data to the TupleOutput (a DatabaseEntry).
		// Order is important. The first data written will be
		// the first bytes used by the default comparison routines.
		out.writeInt(v.getId());
		out.writeString(v.getDescription());
	}

}
